package com.mid;

import java.util.Random;

/**
 * Created by Lxk on 2019/8/10.
 */
public class Solution478 {

    /**
     * 半径
     */
    private double radius;
    /**
     * x坐标
     */
    private double x_center;
    /**
     * y坐标
     */
    private double y_center;

    public Solution478(double radius, double x_center, double y_center) {
        this.radius = radius;
        this.x_center = x_center;
        this.y_center = y_center;
    }

    public double[] randPoint() {
        Random random = new Random();
        double angle = random.nextDouble() * Math.PI * 2;
        double tempRadius = radius * Math.sqrt(random.nextDouble());
        double[] res = new double[2];
        res[0] = tempRadius * Math.cos(angle) + x_center;
        res[1] = tempRadius * Math.sin(angle) + y_center;
        return res;
    }

    public static void main(String[] args) {
        double x_center = 2.0;
        double y_center = 0.0;
        double radius = 2.0;
        Solution478 solution478 = new Solution478(radius, x_center, y_center);
        for (int i = 0; i < 1000; i++) {
            double[] res = solution478.randPoint();
            double testRes = Math.sqrt((res[0] - x_center) * (res[0] - x_center) + (res[1] - y_center) * (res[1] - y_center));
            if (testRes > radius) {
                System.out.println("===================== error ===================");
            } else {
                System.out.println(res[0] + " " + res[1]);
            }
        }
    }

}
